package panel.weatherDetail
{
	import assists.HtmlText;
	import assists.Lang;
	import assists.TextFieldUtils;
	import assists.URI;
	import assists.resource.ResourceLoader;
	
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.text.TextField;
	
	public class WeatherBoxList extends Sprite
	{
		private var _stage:Stage;
		private var _loader:ResourceLoader;
		private var _lang:Lang;
		private var _uri:URI;
		
		private var boxList:Array;
		
		public function WeatherBoxList(stage:Stage, loader:ResourceLoader, lang:Lang, uri:URI=null)
		{
			_stage = stage;
			_loader = loader;
			_lang = lang;
			_uri = uri;
			
			boxList = [];
		}
		
		public function changeData(list:Array):void
		{
			if(list.length > 0){
				var box:WeatherBox;
				
				var hei:int = _stage.stageWidth * .05;
				
				for(var i:int = 0;i < list.length;i++){
					box = new WeatherBox(_stage,_loader,_lang,_uri);
					box.id = i;
					box.changeData(list[i]);
					boxList.push(box);
					
					this.addChild(box);
					box.x = _stage.stageWidth * .05;
					box.y = hei;
					
					hei = hei + box.height + _stage.stageWidth * .05;
				}
			}else{
				addNullBox();
			}
		}
		
		private function addNullBox():void
		{
			var img:Bitmap = new _loader.uiManager.weatherBack as Bitmap;
			img.width = _stage.stageWidth * .8;
			img.height = _stage.stageHeight * .3;
			this.addChild(img);
			
			img.x = _stage.stageWidth * .1;
			img.y = _stage.stageHeight * .25;
			
			var nullText:TextField = new TextField;
			nullText.wordWrap = true;
			nullText.multiline = true;
			nullText.mouseEnabled = false;
			nullText.width = _stage.stageWidth * .7;
			nullText.height = _stage.stageHeight * .25;
			nullText.x = _stage.stageWidth * .15;
			nullText.y = _stage.stageHeight * .3;
			TextFieldUtils.setHtmlText(nullText,HtmlText.formatSizeColor("暂时未能成功获取天气信息，请稍等片刻或检查网络状况",0xFFFF00,18));
			this.addChild(nullText);
		}
		
		public function clear():void
		{
			for(var i:int = 0;i < boxList.length;i++){
				boxList[i].clear();
			}
		}
	}
}